package factory.controller;

import codeManageInfo.dto.AddCodeDTO;
import codeManageInfo.dto.QueryDTO;
import factory.service.CodeManageService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import jakarta.annotation.Resource;
import lombok.extern.slf4j.Slf4j;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;
import result.PageDTO;
import result.R;

@Slf4j
@RestController
@Tag(name = "码值管理",description = "码值管理")
@RequestMapping("/codeManage")
public class CodeManageController {
    @Resource
    private CodeManageService codeManageService;

    @Operation(summary = "分页查询所有码表",description = "分页查询所有码表")
    @PostMapping("/pageAll")
    public R pageAll(@RequestBody PageDTO pageDTO){
       return  R.OK(codeManageService.pageAll(pageDTO));
    }

    @Operation(summary = "条件分页查询所有码表",description = "条件分页查询所有码表")
    @PostMapping("/pageAllByQuery")
    public R pageAllByQuery(@RequestBody QueryDTO queryDTO){
        return  R.OK(codeManageService.pageAllByQuery(queryDTO));
    }

    @Operation(summary = "根据码表id查询码值表",description = "根据码表id查询码值表")
    @PostMapping("/getConfigurationByCodeId")
    public R getConfigurationByCodeId(Integer codeId){
        return  R.OK(codeManageService.getConfigurationByCodeId(codeId));
    }

    @Operation(summary = "删除一条数据",description = "删除一条数据")
    @PostMapping("/deleteCode")
    public R deleteCode(Integer id){
        return codeManageService.removeById(id)?R.OK():R.FAIL();
    }

    @Operation(summary = "添加一条数据",description = "添加一条数据")
    @PostMapping("/addCode")
    public R addCode(@RequestBody AddCodeDTO addCodeDTO){
        return codeManageService.addCode(addCodeDTO)?R.OK():R.FAIL();
    }

    @Operation(summary = "修改一条数据",description = "修改一条数据")
    @PostMapping("/updateCode/{id}")
    public R updateCode(@PathVariable Integer id, @RequestBody AddCodeDTO addCodeDTO){
        return codeManageService.updateCode(id,addCodeDTO)?R.OK():R.FAIL();
    }

    @Operation(summary = "更改数据源状态",description = "更改数据源状态")
    @PostMapping("/updateStatic/{id}")
    public R updateStatic(@PathVariable Integer id){
        return codeManageService.updateStatic(id)?R.OK():R.FAIL();
    }
}
